import React from "react";
import PropTypes from "prop-types";
import Image from "../../component/base/Image";

/**
 *  Logo Component
 */
export default class Logo extends React.Component
{
    /**
     * 组件类名
     */
    className = "logo";

    /**
     * 默认属性
     */
    static defaultProps =
    {
        class : "",
        type : "text",
        children : "Logo",
        src : "",
        alt : "",
        width : "100%",
        height : "100%",
        style : {}
    };

    /**
     * 属性类型
     */
    static propTypes =
    {
        class : PropTypes.string,
        type : PropTypes.oneOf(["text", "image"]).isRequired,
        src : PropTypes.string,
        style : PropTypes.object
    };

    /**
     * 即将挂载组件
     */
    componentWillMount ()
    {
        if ("text" === this.props.type) {
            this.className += " logo-text";
        }

        if (this.props.class) {
            this.className += " " + this.props.class;
        }
    }

    render ()
    {
        return <div className={this.className} style={this.props.style}>
            {this.renderChildren()}
        </div>
    }

    renderChildren ()
    {
        if ("image" === this.props.type) {
            return <Image src={this.props.src} alt={this.props.alt} width={this.props.width} height={this.props.height}/>
        }

        return this.props.children;
    }
}